<?php
class C_groupdiv extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_groupdiv');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$this->load->view('v_groupdiv');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['groupdiv_nama'] = nosql_post("groupdiv_nama");
		echo $this->m_groupdiv->_list($data);
	}
	
	function _insert(){
		$data = array(
			'groupdiv_nama' => $this->input->post('groupdiv_nama'), 
			  
			'groupdiv_active'=> 'y',
			'groupdiv_insert_user'	=>$_SESSION[SESSION_USERNAMA],
			'groupdiv_insert_date'=> date("Y-m-d h:i:s")
		);
		$this->m_groupdiv->_insert($data);
		echo 1;
	}
	
	function _update(){
		$groupdiv_id = $this->input->post('groupdiv_id');
		$divisi = $this->input->post('divisi');
		$data = array(
			'groupdiv_nama' => $this->input->post('groupdiv_nama'), 
			
			'groupdiv_update_user'	=>$_SESSION[SESSION_USERNAMA],
			'groupdiv_update_date'=> date("Y-m-d h:i:s")
		);
		$this->m_groupdiv->_update($data,$groupdiv_id,$divisi);
		echo 1;
 	}
	
	function _delete(){
		$groupdiv_id= $this->input->post('div_id');
		$data = array(
			'groupdiv_active' => 'n'
		);
		$this->m_groupdiv->_delete($data,$groupdiv_id);
		echo 1;
	}
}